qui(
    function (require, exports, module) {
        WrapSys.AccurateFrame = (function () {
            // var adAccurate = {};
            var openFlag = false;
            var adAccurateFrame = {
                'head': '', //打点精确化起始帧
                'end': '', //打点精确化结束帧
                'endSetted': false,
                'headSetted': false
            }
            var params = ["fragment-l", "fragment-r", "ad-l", "ad-r",'p-r','p-l'];
            var accurateFrame = {
                'head': '', //打点精确化起始帧
                'end': '', //打点精确化结束帧
                'endSetted': false,
                'headSetted': false
            }
            //搭建js与flash互通的环境
            function thisMovie(movieName) {
                if (navigator.appName.indexOf("Microsoft") != -1) {
                    return window[movieName];
                } else {
                    return document[movieName];
                }
            }

            function doReset() {
                accurateFrame = {
                    'head': '', //打点精确化起始帧
                    'end': '', //打点精确化结束帧
                    'endSetted': false,
                    'headSetted': false
                }
            }

            function accurateStartEndRemove() {
                openFlag= false;
                var frameId = thisMovie('accurateStartEndFrame').get_select_index();
                if ($('.red').length == 1) {
                    if (frameId == -1) {
                        frameId = '';
                    }
                    var redParent = $('.red').parent();
                    var picId = parseInt( $('.red').parent().find(".pid").text());
                    if (redParent.find(".p-l").length > 0) {
                        accurateFrame.head = frameId;
                        if (accurateFrame.head){
                            accurateFrame.headSetted = true;
                            accurateFrame.headPic = picId
                        }
                    }else if (redParent.find(".p-r").length > 0) {
                        accurateFrame.end = frameId;
                        if (accurateFrame.end){
                            accurateFrame.endSetted = true;
                            accurateFrame.endPic = picId;
                        }
                    }else if (redParent.find(".ad-l").length > 0) {
                        adAccurateFrame.head = frameId;
                        if (adAccurateFrame.head){
                            adAccurateFrame.headSetted = true;
                            adAccurateFrame.headPic = picId
                        }
                    }else if (redParent.find(".ad-r").length > 0) {
                        adAccurateFrame.end = frameId;
                        if (adAccurateFrame.end){
                            adAccurateFrame.endSetted = true;
                            adAccurateFrame.endPic = picId;
                        }
                    }
                }else if ($(".shim-img-selected").length == 1) {
                    var entityId = parseInt($(".shim-img-selected").find("span.shim").attr("sourceId"));
                    WrapSys.ShimManager.modifyEntity(entityId,{ "insertFrameId":frameId }  )
                }
                $('#accurateStartEndOutDiv').css({
                    'left': '-10000px',
                    'top': '-10000px'
                });
            }

            // 打点精确化数据加载
            function accurateStartEndPlay(imgSrc) {
                var analysis = WrapSys.Dao.getDotData().analysis;
                $('#accurateStartEndOutDiv').css({
                    'left': '0px',
                    'top': '0px'
                });
                thisMovie('accurateStartEndFrame').change_flv_url(analysis + "?file=" + imgSrc + "&from_client=true");
                openFlag=true;
            }

            function getAccurateFrame() {
                return accurateFrame;
            }

            function updateAccurateFrame(options) {
                WrapSys.Util.updateObjectData(options, accurateFrame)
            }

            function getAdAccurate() {
                return adAccurateFrame;
            }

            // has marked ad will be removed
            function adTipRemove() {
                $('.ad-l').remove();
                $('.ad-r').remove();
                adAccurateFrame = {
                    'head': '', //打点精确化起始帧
                    'end': '', //打点精确化结束帧
                    'endSetted': false,
                    'headSetted': false
                }
            }

            // has marked fragment will be removed
            function fgTipRemove() {
                $('.fragment-l').remove();
                $('.fragment-r').remove();
            }

            function handler_keyCodeQ() {
                var selected = $(".red").parent();
                $.each(params, function (i, element) {
                    if(selected.find("."+element).length > 0){
                        accurateStartEndPlay(selected.find("img").attr("src"));
                    }
                })
            }


            function readFrameData(frameData){
                accurateFrame = $.extend(true,{},frameData);
            }

            function handler_keyCodeQ_shim() {
                var entityId = parseInt($(".shim-img-selected").find("span.shim").attr("sourceId"));
                var entity = WrapSys.ShimManager.getEntity(entityId);
                accurateStartEndPlay($("#img-" + entity.relationPic).attr("src"));
            }

            function getAdDrop() {
                var ret = { head:null,end:null };
                if(accurateFrame.headSetted){
                    ret.head = {list:[accurateFrame.headPic],head:accurateFrame.head,end:""};
                }
                if(accurateFrame.endSetted){
                    ret.end = {list:[accurateFrame.endPic],end:accurateFrame.end,head:""}
                }
                return ret;
            }
            function isDlgOpen(){
                return openFlag
            }
            return {
                accurateStartEndPlay: accurateStartEndPlay,
                accurateStartEndRemove: accurateStartEndRemove,
                getAccurateFrame: getAccurateFrame,
                updateAccurateFrame: updateAccurateFrame,
                getAdAccurate: getAdAccurate,
                adTipRemove: adTipRemove,
                fgTipRemove: fgTipRemove,
                handler_keyCodeQ: handler_keyCodeQ,
                doReset: doReset,
                readFrameData: readFrameData,
                handler_keyCodeQ_shim: handler_keyCodeQ_shim,
                getAdDrop: getAdDrop,
                isDlgOpen:isDlgOpen
            }
        })()
    }
);